package com.company;

import java.sql.*;
import java.util.ArrayList;
import org.json.JSONObject;

public class some_version_json {
    public static void main(String[] args){
        ArrayList<String> strout = new ArrayList<String>();
        for(int i=1;i<10;i++){
            strout.add(String.format("diagnose_record_20170%d",i));
        }
        for(int i=10;i<13;i++){
            strout.add(String.format("diagnose_record_2017%d",i));
        }
        for(int i=1;i<4;i++){
            strout.add(String.format("diagnose_record_20180%d",i));
        }

        for(int i=0;i<15;i++){
            some_version_json svj = new some_version_json(strout.get(i));
        }

    }
    public static final String url = "jdbc:mysql://rm-wz9v9e07mh753tk321o.mysql.rds.aliyuncs.com:3306/ait";
    // 驱动程序名
    public static final String name = "com.mysql.jdbc.Driver";
    // MySQL配置时的用户名
    public static final String user = "diagnose_report";
    // MySQL配置时的密码
    public static final String password = "launch@1234";

    public Connection conn = null;
    public PreparedStatement pst = null;
    public ResultSet rs= null;
    public Statement stmt = null;
    public some_version_json(String Str_in){
        Connection conn = null;
        PreparedStatement pst = null;
        ResultSet rs= null;
        ResultSet rs1= null;
        Statement stmt = null;
        Statement stmt_out = null;
        String sql ="select diagnose_record_id,software_version,firmware_edition,apk_version,system_version from "+Str_in+";";
        Integer count = 0;
        try {
            Class.forName(name);// 指定连接类型
            conn = DriverManager.getConnection(url, user, password);// 获取连
            stmt = conn.createStatement();
            stmt_out = conn.createStatement();
            rs = stmt.executeQuery(sql);
            while(rs.next()){
                JSONObject jsonObj = new JSONObject();
                String value =rs.getString("software_version");
                jsonObj.put("software_version", value);

                String value1 =rs.getString("firmware_edition");
                jsonObj.put("firmware_edition", value1);

                String value2 =rs.getString("apk_version");
                jsonObj.put("apk_version", value2);

                String value3 =rs.getString("system_version");
                jsonObj.put("system_version", value3);

                String updata_sql = String.format("update %s set some_version = '%s' where diagnose_record_id = %d;",Str_in, jsonObj.toString(),rs.getInt("diagnose_record_id"));
                System.out.println(updata_sql);
                try{

                    stmt_out.executeUpdate(updata_sql);
                } catch (SQLException e) {
                    System.out.println("PreparedStatement 对象创建失败 。。。。");
                    e.printStackTrace();

                }








            }

        }catch (Exception e) {
            e.printStackTrace();
        }


    }
}
